home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / CMatrix.h < prev    next >
C/C++ Source or Header  |  1997-03-07  |  13KB  |  379 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_ComplexMatrix_h)
  24. #define octave_ComplexMatrix_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include "MArray2.h"
  31. #include "MDiagArray2.h"
  32.  
  33. #include "mx-defs.h"
  34. #include "oct-cmplx.h"
  35.  
  36. class ComplexMatrix : public MArray2<Complex>
  37. {
  38. friend class Matrix;
  39. friend class ComplexCHOL;
  40. friend class ComplexHESS;
  41. friend class ComplexLU;
  42. friend class ComplexQR;
  43. friend class ComplexQRP;
  44. friend class ComplexSCHUR;
  45. friend class ComplexSVD;
  46.  
  47. public:
  48.  
  49.   ComplexMatrix (void) : MArray2<Complex> () { }
  50.   ComplexMatrix (int r, int c) : MArray2<Complex> (r, c) { }
  51.   ComplexMatrix (int r, int c, const Complex& val)
  52.     : MArray2<Complex> (r, c, val) { }
  53.   ComplexMatrix (const Matrix& a);
  54.   ComplexMatrix (const MArray2<Complex>& a) : MArray2<Complex> (a) { }
  55.   ComplexMatrix (const ComplexMatrix& a) : MArray2<Complex> (a) { }
  56.   ComplexMatrix (const RowVector& rv);
  57.   ComplexMatrix (const ColumnVector& cv);
  58.   ComplexMatrix (const DiagMatrix& a);
  59.   //  ComplexMatrix (const MDiagArray2<Complex>& a) : MArray2<Complex> (a) { }
  60.   ComplexMatrix (const ComplexRowVector& rv);
  61.   ComplexMatrix (const ComplexColumnVector& cv);
  62.   ComplexMatrix (const ComplexDiagMatrix& a);
  63.  
  64.   ComplexMatrix (const charMatrix& a);
  65.  
  66.   ComplexMatrix& operator = (const ComplexMatrix& a)
  67.     {
  68.       MArray2<Complex>::operator = (a);
  69.       return *this;
  70.     }
  71.  
  72.   bool operator == (const ComplexMatrix& a) const;
  73.   bool operator != (const ComplexMatrix& a) const;
  74.  
  75.   // destructive insert/delete/reorder operations
  76.  
  77.   ComplexMatrix& insert (const Matrix& a, int r, int c);
  78.   ComplexMatrix& insert (const RowVector& a, int r, int c);
  79.   ComplexMatrix& insert (const ColumnVector& a, int r, int c);
  80.   ComplexMatrix& insert (const DiagMatrix& a, int r, int c);
  81.  
  82.   ComplexMatrix& insert (const ComplexMatrix& a, int r, int c);
  83.   ComplexMatrix& insert (const ComplexRowVector& a, int r, int c);
  84.   ComplexMatrix& insert (const ComplexColumnVector& a, int r, int c);
  85.   ComplexMatrix& insert (const ComplexDiagMatrix& a, int r, int c);
  86.  
  87.   ComplexMatrix& fill (double val);
  88.   ComplexMatrix& fill (const Complex& val);
  89.   ComplexMatrix& fill (double val, int r1, int c1, int r2, int c2);
  90.   ComplexMatrix& fill (const Complex& val, int r1, int c1, int r2, int c2);
  91.  
  92.   ComplexMatrix append (const Matrix& a) const;
  93.   ComplexMatrix append (const RowVector& a) const;
  94.   ComplexMatrix append (const ColumnVector& a) const;
  95.   ComplexMatrix append (const DiagMatrix& a) const;
  96.  
  97.   ComplexMatrix append (const ComplexMatrix& a) const;
  98.   ComplexMatrix append (const ComplexRowVector& a) const;
  99.   ComplexMatrix append (const ComplexColumnVector& a) const;
  100.   ComplexMatrix append (const ComplexDiagMatrix& a) const;
  101.  
  102.   ComplexMatrix stack (const Matrix& a) const;
  103.   ComplexMatrix stack (const RowVector& a) const;
  104.   ComplexMatrix stack (const ColumnVector& a) const;
  105.   ComplexMatrix stack (const DiagMatrix& a) const;
  106.  
  107.   ComplexMatrix stack (const ComplexMatrix& a) const;
  108.   ComplexMatrix stack (const ComplexRowVector& a) const;
  109.   ComplexMatrix stack (const ComplexColumnVector& a) const;
  110.   ComplexMatrix stack (const ComplexDiagMatrix& a) const;
  111.  
  112.   ComplexMatrix hermitian (void) const;  // complex conjugate transpose
  113.   ComplexMatrix transpose (void) const;
  114.  
  115.   friend ComplexMatrix conj (const ComplexMatrix& a);
  116.  
  117.   // resize is the destructive equivalent for this one
  118.  
  119.   ComplexMatrix extract (int r1, int c1, int r2, int c2) const;
  120.  
  121.   // extract row or column i.
  122.  
  123.   ComplexRowVector row (int i) const;
  124.   ComplexRowVector row (char *s) const;
  125.  
  126.   ComplexColumnVector column (int i) const;
  127.   ComplexColumnVector column (char *s) const;
  128.  
  129.   ComplexMatrix inverse (void) const;
  130.   ComplexMatrix inverse (int& info) const;
  131.   ComplexMatrix inverse (int& info, double& rcond, int force = 0) const;
  132.  
  133.   ComplexMatrix pseudo_inverse (double tol = 0.0);
  134.  
  135.   ComplexMatrix fourier (void) const;
  136.   ComplexMatrix ifourier (void) const;
  137.  
  138.   ComplexMatrix fourier2d (void) const;
  139.   ComplexMatrix ifourier2d (void) const;
  140.  
  141.   ComplexDET determinant (void) const;
  142.   ComplexDET determinant (int& info) const;
  143.   ComplexDET determinant (int& info, double& rcond) const;
  144.  
  145.   ComplexMatrix solve (const Matrix& b) const;
  146.   ComplexMatrix solve (const Matrix& b, int& info) const;
  147.   ComplexMatrix solve (const Matrix& b, int& info, double& rcond) const;
  148.  
  149.   ComplexMatrix solve (const ComplexMatrix& b) const;
  150.   ComplexMatrix solve (const ComplexMatrix& b, int& info) const;
  151.   ComplexMatrix solve (const ComplexMatrix& b, int& info, double& rcond) const;
  152.  
  153.   ComplexColumnVector solve (const ComplexColumnVector& b) const;
  154.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info) const;
  155.   ComplexColumnVector solve (const ComplexColumnVector& b, int& info,
  156.                  double& rcond) const;
  157.  
  158.   ComplexMatrix lssolve (const ComplexMatrix& b) const;
  159.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info) const;
  160.   ComplexMatrix lssolve (const ComplexMatrix& b, int& info,
  161.              int& rank) const;
  162.  
  163.   ComplexColumnVector lssolve (const ComplexColumnVector& b) const;
  164.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info) const;
  165.   ComplexColumnVector lssolve (const ComplexColumnVector& b, int& info,
  166.                    int& rank) const;
  167.  
  168.   ComplexMatrix expm (void) const;
  169.  
  170.   // column vector by row vector -> matrix operations
  171.  
  172.   friend ComplexMatrix operator * (const ColumnVector& a,
  173.                    const ComplexRowVector& b);
  174.  
  175.   friend ComplexMatrix operator * (const ComplexColumnVector& a,
  176.                    const RowVector& b);
  177.  
  178.   friend ComplexMatrix operator * (const ComplexColumnVector& a,
  179.                    const ComplexRowVector& b);
  180.  
  181.   // diagonal matrix by scalar -> matrix operations
  182.  
  183.   friend ComplexMatrix operator + (const DiagMatrix& a, const Complex& s);
  184.   friend ComplexMatrix operator - (const DiagMatrix& a, const Complex& s);
  185.  
  186.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a, double s);
  187.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a, double s);
  188.  
  189.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a,
  190.                    const Complex& s);
  191.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a,
  192.                    const Complex& s);
  193.  
  194.   // scalar by diagonal matrix -> matrix operations
  195.  
  196.   friend ComplexMatrix operator + (const Complex& s, const DiagMatrix& a);
  197.   friend ComplexMatrix operator - (const Complex& s, const DiagMatrix& a);
  198.  
  199.   friend ComplexMatrix operator + (double s, const ComplexDiagMatrix& a);
  200.   friend ComplexMatrix operator - (double s, const ComplexDiagMatrix& a);
  201.  
  202.   friend ComplexMatrix operator + (const Complex& s,
  203.                    const ComplexDiagMatrix& a);
  204.   friend ComplexMatrix operator - (const Complex& s,
  205.                    const ComplexDiagMatrix& a);
  206.  
  207.   // matrix by diagonal matrix -> matrix operations
  208.  
  209.   ComplexMatrix& operator += (const DiagMatrix& a);
  210.   ComplexMatrix& operator -= (const DiagMatrix& a);
  211.  
  212.   ComplexMatrix& operator += (const ComplexDiagMatrix& a);
  213.   ComplexMatrix& operator -= (const ComplexDiagMatrix& a);
  214.  
  215.   friend ComplexMatrix operator + (const Matrix& a,
  216.                    const ComplexDiagMatrix& b); 
  217.   friend ComplexMatrix operator - (const Matrix& a,
  218.                    const ComplexDiagMatrix& b);
  219.   friend ComplexMatrix operator * (const Matrix& a,
  220.                    const ComplexDiagMatrix& b);
  221.  
  222.   // diagonal matrix by matrix -> matrix operations
  223.  
  224.   friend ComplexMatrix operator + (const DiagMatrix& a,
  225.                    const ComplexMatrix& b);
  226.   friend ComplexMatrix operator - (const DiagMatrix& a,
  227.                    const ComplexMatrix& b);
  228.   friend ComplexMatrix operator * (const DiagMatrix& a,
  229.                    const ComplexMatrix& b);
  230.  
  231.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a,
  232.                    const Matrix& b); 
  233.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a,
  234.                    const Matrix& b);
  235.   friend ComplexMatrix operator * (const ComplexDiagMatrix& a,
  236.                    const Matrix& b);
  237.  
  238.   friend ComplexMatrix operator + (const ComplexDiagMatrix& a,
  239.                    const ComplexMatrix& b);
  240.   friend ComplexMatrix operator - (const ComplexDiagMatrix& a,
  241.                    const ComplexMatrix& b);
  242.   friend ComplexMatrix operator * (const ComplexDiagMatrix& a,
  243.                    const ComplexMatrix& b);
  244.  
  245.   // matrix by matrix -> matrix operations
  246.  
  247.   ComplexMatrix& operator += (const Matrix& a);
  248.   ComplexMatrix& operator -= (const Matrix& a);
  249.  
  250.   ComplexMatrix& operator += (const ComplexMatrix& a);
  251.   ComplexMatrix& operator -= (const ComplexMatrix& a);
  252.  
  253.   // unary operations
  254.  
  255.   Matrix operator ! (void) const;
  256.  
  257.   // matrix by scalar -> matrix operations
  258.  
  259.   friend ComplexMatrix operator + (const Matrix& a, const Complex& s);
  260.   friend ComplexMatrix operator - (const Matrix& a, const Complex& s);
  261.   friend ComplexMatrix operator * (const Matrix& a, const Complex& s);
  262.   friend ComplexMatrix operator / (const Matrix& a, const Complex& s);
  263.  
  264.   friend ComplexMatrix operator + (const ComplexMatrix& a, double s);
  265.   friend ComplexMatrix operator - (const ComplexMatrix& a, double s);
  266.   friend ComplexMatrix operator * (const ComplexMatrix& a, double s);
  267.   friend ComplexMatrix operator / (const ComplexMatrix& a, double s);
  268.  
  269.   // scalar by matrix -> matrix operations
  270.  
  271.   friend ComplexMatrix operator + (double s, const ComplexMatrix& a);
  272.   friend ComplexMatrix operator - (double s, const ComplexMatrix& a);
  273.   friend ComplexMatrix operator * (double s, const ComplexMatrix& a);
  274.   friend ComplexMatrix operator / (double s, const ComplexMatrix& a);
  275.  
  276.   friend ComplexMatrix operator + (const Complex& s, const Matrix& a);
  277.   friend ComplexMatrix operator - (const Complex& s, const Matrix& a);
  278.   friend ComplexMatrix operator * (const Complex& s, const Matrix& a);
  279.   friend ComplexMatrix operator / (const Complex& s, const Matrix& a);
  280.  
  281.   // matrix by diagonal matrix -> matrix operations
  282.  
  283.   friend ComplexMatrix operator + (const ComplexMatrix& a,
  284.                    const DiagMatrix& b);
  285.   friend ComplexMatrix operator - (const ComplexMatrix& a,
  286.                    const DiagMatrix& b);
  287.   friend ComplexMatrix operator * (const ComplexMatrix& a,
  288.                    const DiagMatrix& b);
  289.  
  290.   friend ComplexMatrix operator + (const ComplexMatrix& a,
  291.                    const ComplexDiagMatrix& b);
  292.   friend ComplexMatrix operator - (const ComplexMatrix& a,
  293.                    const ComplexDiagMatrix& b);
  294.   friend ComplexMatrix operator * (const ComplexMatrix& a,
  295.                    const ComplexDiagMatrix& b);
  296.  
  297.   // matrix by matrix -> matrix operations
  298.  
  299.   friend ComplexMatrix operator + (const ComplexMatrix& a, const Matrix& b);
  300.   friend ComplexMatrix operator - (const ComplexMatrix& a, const Matrix& b);
  301.  
  302.   friend ComplexMatrix operator + (const Matrix& a, const ComplexMatrix& b);
  303.   friend ComplexMatrix operator - (const Matrix& a, const ComplexMatrix& b);
  304.  
  305.   friend ComplexMatrix operator * (const ComplexMatrix& a, const Matrix& b);
  306.  
  307.   friend ComplexMatrix operator * (const Matrix& a, const ComplexMatrix& b);
  308.  
  309.   friend ComplexMatrix operator * (const ComplexMatrix& a,
  310.                    const ComplexMatrix& b);
  311.  
  312.   friend ComplexMatrix product (const ComplexMatrix& a, const Matrix& b);
  313.   friend ComplexMatrix quotient (const ComplexMatrix& a, const Matrix& b);
  314.  
  315.   friend ComplexMatrix product (const Matrix& a, const ComplexMatrix& b);
  316.   friend ComplexMatrix quotient (const Matrix& a, const ComplexMatrix& b);
  317.  
  318.   // other operations
  319.  
  320.   ComplexMatrix map (c_c_Mapper f) const;
  321.   Matrix map (d_c_Mapper f) const;
  322.  
  323.   ComplexMatrix& apply (c_c_Mapper f);
  324.  
  325.   bool any_element_is_inf_or_nan (void) const;
  326.   bool all_elements_are_real (void) const;
  327.   bool all_integers (double& max_val, double& min_val) const;
  328.   bool too_large_for_float (void) const;
  329.  
  330.   Matrix all (void) const;
  331.   Matrix any (void) const;
  332.  
  333.   ComplexMatrix cumprod (void) const;
  334.   ComplexMatrix cumsum (void) const;
  335.   ComplexMatrix prod (void) const;
  336.   ComplexMatrix sum (void) const;
  337.   ComplexMatrix sumsq (void) const;
  338.  
  339.   ComplexColumnVector diag (void) const;
  340.   ComplexColumnVector diag (int k) const;
  341.  
  342.   bool row_is_real_only (int) const;
  343.   bool column_is_real_only (int) const;
  344.  
  345.   ComplexColumnVector row_min (void) const;
  346.   ComplexColumnVector row_max (void) const;
  347.  
  348.   ComplexColumnVector row_min (Array<int>& index) const;
  349.   ComplexColumnVector row_max (Array<int>& index) const;
  350.  
  351.   ComplexRowVector column_min (void) const;
  352.   ComplexRowVector column_max (void) const;
  353.  
  354.   ComplexRowVector column_min (Array<int>& index) const;
  355.   ComplexRowVector column_max (Array<int>& index) const;
  356.  
  357.   // i/o
  358.  
  359.   friend ostream& operator << (ostream& os, const ComplexMatrix& a);
  360.   friend istream& operator >> (istream& is, ComplexMatrix& a);
  361.  
  362. private:
  363.  
  364.   ComplexMatrix (Complex *d, int r, int c) : MArray2<Complex> (d, r, c) { }
  365. };
  366.  
  367. ComplexMatrix Givens (const Complex&, const Complex&);
  368.  
  369. ComplexMatrix Sylvester (const ComplexMatrix&, const ComplexMatrix&,
  370.              const ComplexMatrix&);
  371.  
  372. #endif
  373.  
  374. /*
  375. ;;; Local Variables: ***
  376. ;;; mode: C++ ***
  377. ;;; End: ***
  378. */
  379.